//
//  TMPreferencesController.m
//  Textmaster
//
//  Created by Anshu Chimala on 1/2/10.
//  Copyright 2010 Home. All rights reserved.
//

#import "TMPreferencesController.h"
#import "TMPreferences.h"
#import "TextmasterAppDelegate.h"

@implementation TMPreferencesController

- (void)awakeFromNib {
	[_pasteTextCheckbox setState:[TMPreferences pasteTextAfterSearching]];
	[_filterByDescriptionCheckbox setState:[TMPreferences filterByDescription]];
	[_checkForUpdatesCheckbox setState:[TMPreferences checkForUpdates]];
	[_openAtLoginCheckbox setState:[TMPreferences openAtLogin]];
	[_shortcutRecorder setKeyCombo:[TMPreferences shortcutKeyCombo]];
}

- (IBAction)updateTextPastingPreference:(id)sender {
	[TMPreferences setPasteTextAfterSearching:[_pasteTextCheckbox state] == NSOnState];
}

- (IBAction)updateDescriptionFilteringPreference:(id)sender {
	[TMPreferences setFilterByDescription:[_filterByDescriptionCheckbox state] == NSOnState];
}

- (IBAction)updateUpdateCheckingPreference:(id)sender {
	[TMPreferences setCheckForUpdates:[_checkForUpdatesCheckbox state] == NSOnState];
}

- (void)shortcutRecorder:(SRRecorderControl *)aRecorder keyComboDidChange:(KeyCombo)newKeyCombo {
	TextmasterAppDelegate *delegate = (TextmasterAppDelegate *)[NSApp delegate];
	[delegate setKeyCombo:newKeyCombo];
}

- (IBAction)updateOpeningAtLoginPreference:(id)sender {
	[TMPreferences setOpenAtLogin:[_openAtLoginCheckbox state] == NSOnState];
}

- (IBAction)openMacroFolder:(id)sender {
	[_preferencesScreen orderOut:nil];
	[[NSWorkspace sharedWorkspace] openFile:[@"~/Library/Application Support/Textmaster/PlugIns" stringByExpandingTildeInPath]];
}

@end
